package sms

import (
	"errors"
	"strings"
)

// SMS 短信对象
type SMS interface {
	SendSMSCode(phone, code string) error
	SendTplMessage(phone, tplId string, tplValue map[string]string) error
}

// 统一注册短信驱动
var config = map[string]func() SMS{}

// NewSMS 创建短信对象
func NewSMS(drive string) (SMS, error) {
	if f, ok := config[drive]; ok {
		return f(), nil
	}
	return nil, errors.New("not support this drive: " + drive)
}

// IsChinaPhone 判断是否是中国的手机号
func IsChinaPhone(mobile string) bool {
	return strings.HasPrefix(mobile, "+86")
}
